// pages/comments/comments.js
var ports = require("../../utils/ports.js")
var app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    goodsShopID: '',
    ObjectDiscussList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var id = options.id;
    if (id) {
      that.setData({
        goodsShopID: id
      })
      that.getObjectDiscussList(id)
    } else {
      wx.showToast({
        title: '参数异常',
        icon: 'none'
      })
      setTimeout(function () {
        wx.navigateBack()
      }, 1000)
    }
  },
  //评论记录
  getObjectDiscussList(objectID) {
    var that = this
    var sessionID = wx.getStorageSync('USER_SESSIONID')
    if (sessionID) {
      //评论
      var req = {}
      req.ListName = 'ObjectDiscussList'
      req.objectID = objectID
      req.sortTypeTime = 1
      ports.ModuleDiscuss.getObjectDiscussList(req, that, res => {
        if (res.data.header.code == 0) {
          that.setData({
            ObjectDiscussList: res.data.body.data.rows
          })
        }
      })
    }
  },

  /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
  onPullDownRefresh: function () {
    var that = this;
    ports.ModuleAll.PullDownRefresh(that, () => {
      that.getObjectDiscussList(that.data.goodsShopID)
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    ports.ModuleAll.ReachBottom('ObjectDiscussList', that, res => {
      that.getObjectDiscussList(that.data.goodsShopID)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})